package examples
{
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import com.wskeee.ec.components.Button;
	import com.wskeee.ec.components.HScrollBar;
	import com.wskeee.ec.components.Label;
	import com.wskeee.ec.components.VScrollBar;
	import com.wskeee.ec.containers.Container;
	import com.wskeee.ec.containers.GridBox;
	import com.wskeee.ec.containers.HBox;
	import com.wskeee.ec.containers.VBox;
	import com.wskeee.ec.core.EGlobal;

	public class ScrollBarExample 
	{
		public static function createScrollBar():Container
		{
			var mainBox:VBox = new VBox();
			var head:Label = new Label();
			head.text = "ScrollBar";
			mainBox.verticalGap = 20;
			mainBox.paddingTop = mainBox.paddingBottom = mainBox.paddingLeft = mainBox.paddingRight = 5;
			mainBox.addChild(head);
			
			var contentBox:GridBox = new GridBox(2);
			contentBox.autoSize = true;
			var content:GridBox = new GridBox(3);
			var vscrollbar:VScrollBar = new VScrollBar();
			
			/*vscrollbar.setStyle("ArrowUp_upSkin",EGlobal.resourceManager.getElementClass("VScrollArrowUp_upSkin","ecskin"));
			vscrollbar.setStyle("ArrowUp_overSkin",EGlobal.resourceManager.getElementClass("VScrollArrowUp_overSkin","ecskin"));
			vscrollbar.setStyle("ArrowUp_downSkin",EGlobal.resourceManager.getElementClass("VScrollArrowUp_downSkin","ecskin"));
			
			vscrollbar.setStyle("Thumb_upSkin",EGlobal.resourceManager.getElementClass("VScrollThumb_upSkin","ecskin"));
			vscrollbar.setStyle("Thumb_overSkin",EGlobal.resourceManager.getElementClass("VScrollThumb_overSkin","ecskin"));
			vscrollbar.setStyle("Thumb_downSkin",EGlobal.resourceManager.getElementClass("VScrollThumb_downSkin","ecskin"));
			
			vscrollbar.setStyle("ArrowDown_upSkin",EGlobal.resourceManager.getElementClass("VScrollArrowDown_upSkin","ecskin"));
			vscrollbar.setStyle("ArrowDown_overSkin",EGlobal.resourceManager.getElementClass("VScrollArrowDown_overSkin","ecskin"));
			vscrollbar.setStyle("ArrowDown_downSkin",EGlobal.resourceManager.getElementClass("VScrollArrowDown_downSkin","ecskin"));
			
			vscrollbar.setStyle("Track_skin",EGlobal.resourceManager.getElementClass("VScrollTrack_skin","ecskin"));*/
			
			//设置 target 可视区，先设置target 后设置viewarea
			vscrollbar.target = content;
			vscrollbar.viewarea = new Rectangle(0,0,100,100);
			var hscrollbar:HScrollBar = new HScrollBar();
			hscrollbar.target = content;
			hscrollbar.viewarea = new Rectangle(0,0,100,100);
			
			contentBox.addChild(content);
			contentBox.addChild(vscrollbar);
			contentBox.addChild(hscrollbar);
			
			for(var i:int=0;i<3;i++)
			{
				content.addChild(new Button());
			}
			mainBox.addChild(contentBox);
			
			//---------------------
			//control
			//---------------------
			var controlBox:HBox = new HBox();
			var button:Button = new Button();
			button.label = "add";
			button.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent):void
			{
				content.addChild(new Button());
			});
			controlBox.addChild(button);
			
			button = new Button();
			button.label = "remove";
			button.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent):void
			{
				if(content.numChildren>0)
					content.removeChildAt(0);
			});
			controlBox.addChild(button);
			
			button = new Button();
			button.label = "clear";
			button.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent):void
			{
				content.removeAllChildren();
			});
			controlBox.addChild(button);
			mainBox.addChild(controlBox);
			return mainBox;
		}
	}
}